package com.markedquilt.interedu.util;

import com.markedquilt.interedu.enums.ErrorEnum;
import com.markedquilt.interedu.vo.Result;

/**
 * @Description API返回数据工具类
 * @Author coke
 * @Date 2020/3/2 16:26
 **/
public final class JsonUtil {

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("请求成功");
        result.setData(data);
        return result;
    }

    public static Result success(){
        return success(null);
    }

    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static Result error(ErrorEnum errorEnum){
        Result result = new Result();
        result.setCode(errorEnum.getCode());
        result.setMsg(errorEnum.getMsg());
        result.setData(null);
        return result;
    }

}
